import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * @Classname ServerSocketTest
 * @Description
 * @Date 2020-09-03 13:35
 * @Created by myc
 */
public class ServerSocketTest {

    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket  = new ServerSocket(8080);
        while (true){
//            System.out.println("开始测试:"+new Date());
            Socket socket = serverSocket.accept();
            new Thread(()->{
                try {
                    handler(socket);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }).start();
//            System.out.println("结束测试:"+new Date());
        }

    }

    private static void handler(Socket socket) throws IOException {
        System.out.println("处理请求");
        BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        String body = null;
        while ((body = reader.readLine()) != null){
            System.out.println(body);
        }
    }
}
